/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package webproxy;

import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author MinhVu
 */
public class Config {
    private Boolean isChangeProxy;
    private Boolean isCache;
    private long MaxSize;
    private long FreeSize;
    private String ChangeProxy_Host;
    private int ChangeProxy_Port;
    private ACL_Filter filter;
    
    public Config()  
    {
        isChangeProxy = false;
        isCache = false;
        ChangeProxy_Host =null;
        ChangeProxy_Port = 0;
        MaxSize = 0;
        FreeSize = 0;
        filter = new ACL_Filter();
    }
    public Config(Config cf)
    {
        isChangeProxy = cf.IsChangeProxy();
        isCache = cf.IsCache();
        MaxSize = cf.getMaxSize();
        FreeSize = cf.getFreeSize();
        ChangeProxy_Host =cf.getChangeProxy_Host();
        ChangeProxy_Port = cf.getChangeProxy_Port();
        filter = cf.getFilter();
    }
    
    //<editor-fold defaultstate="collapsed" desc="Get - Set">
    //-------------- GET ---------------------------
    public Boolean IsCache()
    {
        return isCache;
    }
    public Boolean IsChangeProxy()
    {
        return isChangeProxy;
    }
    public String getChangeProxy_Host()
    {
        return ChangeProxy_Host;
    }
    public int getChangeProxy_Port()
    {
        return ChangeProxy_Port;
    }
    public ACL_Filter getFilter()
    {
        return filter;
    }
    public long getMaxSize()
    {
        return MaxSize;
    }
    public long getFreeSize()
    {
         return FreeSize;
    }
    //------------- SET -------------------------
    public void setCache(Boolean c)
    {
        isCache = c;
    }
    public void setChangeProxy(Boolean b)
    {
        isChangeProxy = b;
    }
    public void setChangeProxy_Host(String host)
    {
        ChangeProxy_Host = host;
    }
    public void setChangeProxy_Port(int port)
    {
     ChangeProxy_Port = port;   
    }
    public void setFilter(ACL_Filter f)
    {
        filter = f;
    }
    public void setMaxSize(long max)
    {
        MaxSize = max;
    }
    public void setFreeSize(long free)
    {
        FreeSize = free;
    }
     //</editor-fold>
    
    public void InputFile(String fileName)
    {
        //Cau truc file config
        //Dong 1: Cache
        //Dong 2: MaxSize Cache
        //Dong 4: FreeSize Cache
        //Dong 5: Change Proxy True or False
        //Dong 6: Host 
        //Dong 7: Port
        //Dong 8: Image
        //Dong 9: Audio
        //Dong 10: Video
        //Dong 11: Flash
        //Dong 12: Lock
        try {
            FileInputStream fis = new FileInputStream(fileName);
            BufferedReader bffr = new BufferedReader(new InputStreamReader(fis));
            try {
                isCache = Boolean.valueOf(bffr.readLine());
                MaxSize = Long.parseLong(bffr.readLine());
                FreeSize = Long.parseLong(bffr.readLine());
                isChangeProxy = Boolean.valueOf(bffr.readLine());
                ChangeProxy_Host = bffr.readLine();
                ChangeProxy_Port = Integer.parseInt(bffr.readLine());
                filter.setImage(Boolean.valueOf(bffr.readLine()));
                filter.setAudio(Boolean.valueOf(bffr.readLine()));
                filter.setVideo(Boolean.valueOf(bffr.readLine()));
                filter.setFlash(Boolean.valueOf(bffr.readLine()));
                filter.setLock(Boolean.valueOf(bffr.readLine()));
                bffr.close();
                fis.close();
            } catch (IOException ex) {
                Logger.getLogger(Config.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Config.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    public void OutputFile(String fileName)
    {
        try {
            FileOutputStream fos = new FileOutputStream(fileName);
            PrintStream ps = new PrintStream(fos);
            ps.println(isCache);
            ps.println(MaxSize);
            ps.println(FreeSize);
            ps.println(isChangeProxy);
            ps.println(ChangeProxy_Host);
            ps.println(ChangeProxy_Port);
            ps.println(filter.getImage());
            ps.println(filter.getAudio());
            ps.println(filter.getVideo());
            ps.println(filter.getFlash());
            ps.println(filter.getLock());
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Config.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }
}
